#include <stdio.h>

union node1
{
    int num;
    char ch;
};

union node2
{
    int num;
    short int s;
};

void endian_test_1()
{
    union node1 p;

    p.num = 0x12345678;
    if (p.ch == 0x78)
    {
        printf("Little endian\n");
    }
    else
    {
        printf("Big endian\n");
    }
}

void endian_test_2()
{
    int num = 0x12345678;
    char *q = (char*)&num;

    if (*q == 0x78)
    {
        printf("Little endian\n");
    }
    else
    {
        printf("Big endian\n");
    }
}

void endian_test_3()
{
	union node2 p;

    p.num = 0x12345678;

	printf("0x%x\r\n", p.s);
}

void main()
{
	printf("endian test ....\r\n");

	endian_test_1();

	endian_test_2();

	endian_test_3();
}

